{layout name="common/base" }
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm data-add-btn"> 新增问题 </button>
        </div>
        <div class="layui-form" style="margin-top: 20px;">
            <table class="layui-table" style="table-layout: fixed;">
                <colgroup>
                    <col width="40">
                    <col minWidth="300">
                    <col width="200">
                    <col width="200">
                </colgroup>
                <thead>
                <tr>
                    <th>ID</th>
                    <th>题目名称</th>
                    <th class="text-center">创建时间</th>
                    <th>操作管理</th>
                </tr>
                </thead>
                <tbody>
                {volist name="list['data']" id="vo"}
                <tr>
                    <td>{$vo.id}</td>
                    <td>{$vo.name}</td>
                    <td>{$vo.create_time}</td>
                    <td>
                        <a class="layui-btn layui-btn-xs data-count-edit edit" lay-event="edit" data-id="{$vo.id}">编辑</a>
                        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete delete" lay-event="delete" data-id="{$vo.id}">删除</a>
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
        </div>
    </div>

    <div id="pages"></div>
</div>
<script src="__PUBLIC__/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    var product_id = '<?php echo $product_id;?>';
    layui.use(['form', 'table', 'laypage'], function () {
        var $ = layui.jquery,
            table = layui.table,
            laypage = layui.laypage;
        laypage.render({ //分页
            elem: 'pages',
            count: '<?php echo $list["total"]; ?>',  // 新加的内容哦。
            theme: '#FFB800',
            //, curr: param['page']
            curr: '<?php echo $list["current_page"]; ?>', // 完美解决哦。
            //,hash: 'page' //自定义hash值
            jump: function(obj, first){
                //obj包含了当前分页的所有参数，比如：
                //首次不执行
                if(!first){
                    //do something
                    location.href="?page="+obj.curr+"&product_id="+product_id
                }
            }
        });

        // 监听添加操作
        $(".data-add-btn").on("click", function () {
            var index = layer.open({
                title: '添加问题',
                type: 2,
                shade: 0.2,
                maxmin:true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: '/admin/question/add/product_id/'+ product_id
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
            return false;
        });
        $('.edit').on('click', function () {
            var id = $(this).attr('data-id'); // fu
            var index = layer.open({
                title: '编辑题目',
                type: 2,
                shade: 0.2,
                maxmin:true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: '/admin/question/edit/id/' + id+'/product_id/'+product_id,
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
        })
        $('.delete').on('click', function () {
            var id = $(this).attr('data-id'); // fu
            layer.confirm('真的删除么?', function (index) {
                $.ajax({
                    url: '/admin/question/del/id/' + id,
                    type: 'GET',
                    success: function(res) {
                        window.location.reload();
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            layer.close(index);
                        });
                    },
                    error: function(res) {
                        //return   err(res)
                    }
                });

            });
        })
    });
</script>
